<html>

<head>
<title>SQL Relay - Getting Started With Microsoft SQL Server</title>
<link rel="stylesheet" href="../css/styles.css">
</head>

<body>

<span class="heading1">Getting Started With Microsoft SQL Server</span><br>

<ul>
<li><a href="#installation">Installation</a></li>
<li><a href="#creating">Creating a Database</a></li>
<li><a href="#accessing">Accessing a Database</a></li>
<ul>
<li><a href="#freetds">FreeTDS</a></li>
<ul>
<li><a href="#freebsd">FreeBSD</a></li>
<li><a href="#openbsd">OpenBSD</a></li>
<li><a href="#netbsd">NetBSD</a></li>
</ul>
<li><a href="#sqsh">SQSH</a></li>
</ul>
<li><a href="#sqlrelay">Accessing a Database With SQL Relay</a></li>
</ul>

<a name="installation"></a>
<span class="heading1">Installation</span><br>

run setup.bat

<a name="creating"></a>
<span class="heading1">Creating a Database</span><br>

<p>more to come...</p>

<a name="installation"></a>
<span class="heading1">Accessing a Database</span><br>

<p>Accessing Microsoft SQL Server from a non-Microsoft platform requires 
the FreeTDS library and a client that uses it such as SQSH.</p>

<a name="freetds"></a>
<span class="heading2">FreeTDS</span><br>

<p>I've sucessfully installed FreeTDS on Linux, FreeBSD, NetBSD, OpenBSD, SCO
OpenServer and Solaris.  I had to compile from source on Linux, SCO OpenServer
and Solaris.  FreeTDS is available from the
<a href="http://www.freetds.org">FreeTDS home page</a>. It compiles cleanly on
all platforms.  When compiling from source, I usually give the 
<i>configure</i> script the <i>--prefix=/usr/local/freetds</i> parameter so 
that FreeTDS will be installed entirely under /usr/local/freetds and then add
/usr/local/freetds/lib to my LD_LIBRARY_PATH environment variable.</p>

<p>FreeBSD, OpenBSD and NetBSD come with FreeTDS and give you the option of
installing it when you install the rest of the system.  If you want or need to
install it afterward, follow the instructions below.</p>

<a name="freebsd"></a>
<span class="heading3">FreeBSD</span><br>

<p>If you have an internet connection, run <i>pkg_add -r freetds</i>.
When the command completes, FreeTDS will be installed.  You can also install
FreeTDS from the Ports CD(s) that came with your distribution using 
<i>/stand/sysinstall</i>.</p>

<a name="openbsd"></a>
<span class="heading3">OpenBSD</span><br>

<p>The freetds package is available from 
<a href="ftp://ftp.openbsd.org">ftp.openbsd.org</a> or on CD's that came with
your distribution. You can install it using <i>pkg_add</i>.</p>

<a name="netbsd"></a>
<span class="heading3">NetBSD</span><br>

<p>The freetds package is available from 
<a href="ftp://ftp.netbsd.org">ftp.netbsd.org</a> or on CD's that came with
your distribution. You can install them using <i>pkg_add</i>.</p>

<a name="sqsh"></a>
<span class="heading2">SQSH</span><br>

<p>I've sucessfully installed SQSH on Linux, FreeBSD, NetBSD, OpenBSD, SCO
OpenServer and Solaris.  On all platforms, I've had to compile it from source.
SQSH is available from the <a href="http://www.sqsh.org">SQSH home page</a>.  
It compiles cleanly on all platforms.</p>

<p>SQSH can be compiled against FreeTDS libraries or Sybase native libraries.
To use SQSH with Microsoft SQL Server, it must be compiled against FreeTDS.
The SQSH configure script uses the SYBASE environment variable to decide where
to look for the necessary include files and libraries.  You must set this
variable before attempting to compile SQSH.  For example, if you installed
FreeTDS in /usr/local/freetds, you can set the environment variable as 
follows.</p>

<p>For Bourne shells:</p>

<blockquote>
<PRE>
<FONT color=#008a8e>SYBASE</FONT>=/usr/local/freetds
<B><FONT color=#a62828>export </FONT></B><FONT color=#008a8e>SYBASE</FONT>
</PRE>
</blockquote>

<p>For C-shells:</p>

<blockquote>
<PRE>
<B><FONT color=#a62828>setenv</FONT></B> <FONT color=#6959cf>SYBASE</FONT> /usr/local/freetds
</PRE>
</blockquote>

<p>I usually give the <i>configure</i> script the 
<i>--prefix=/usr/local/sqsh</i> parameter so that SQSH will be installed 
entirely under /usr/local/sqsh and then add /usr/local/sqsh/bin to my PATH
environment variable.</p>

<p>Once you have FreeTDS and SQSH installed, you can access the database using 
SQSH.  Note that you will need to have the SYBASE environment variable set
when running SQSH.</p>

<p>SQSH requires a <b>username</b>, <b>server</b> and <b>database</b> 
name to access a database.  The <b>server</b> parameter does not refer to the
hostname of the machine you want to connect to, but rather to an entry in the
<i>$SYBASE/interfaces</i> file.  Below is a sample entry for a server named 
<i>remotehost</i> which refers to an instance of Microsoft SQL Server running 
on <i>testhost.testdomain.com</i>, on port 1433, accessible over tcp on 
ethernet.</p>

<blockquote>
<pre><b>
remotehost
	master tcp ether testhost.testdomain.com 1433
	query tcp ether testhost.testdomain.com 1433
</b></pre>
</blockquote>

<p>Similar entries can be made to access servers running on other hosts.</p>

<p>To access the database <i>testdb</i> on the server <i>localhost</i> as the
user <i>testuser</i>, run the following command.</p>

<blockquote>
<b>sqsh -U testuser -S localhost -D testdb</b>
</blockquote>

<p>more to come...</p>

<a name="sqlrelay"></a>
<span class="heading1">Accessing a Database With SQL Relay</span><br>

<p>Accessing Microsoft SQL Server from SQL Relay requires an instance entry in 
your <i>sqlrelay.conf</i> file for the database that you want 
to access.  Here is an example <i>sqlrelay.conf</i> which defines an SQL Relay 
instance called freetdstest.  This instance connects to the <i>testdb</i> 
database on the server <i>remotehost</i> as the user <i>testuser</i> with 
password <i>testpassword</i>.</p>

<PRE>
<FONT color=#0000ff>&lt;?</FONT><B><FONT color=#288a51>xml version=</FONT></B><FONT color=#ff00ff>&quot;1.0&quot;</FONT><FONT color=#0000ff>?&gt;</FONT>
<FONT color=#008a8e>&lt;!</FONT><B><FONT color=#a62828>DOCTYPE</FONT></B> instances <B><FONT color=#a62828>SYSTEM</FONT></B> <FONT color=#ff00ff>&quot;sqlrelay.dtd&quot;</FONT><FONT color=#008a8e>&gt;</FONT>
<FONT color=#008a8e>&lt;instances&gt;</FONT>

        <FONT color=#008a8e>&lt;instance id=</FONT><FONT color=#ff00ff>&quot;freetdstest&quot;</FONT><FONT color=#008a8e> port=</FONT><FONT color=#ff00ff>&quot;9000&quot;</FONT><FONT color=#008a8e> socket=</FONT><FONT color=#ff00ff>&quot;/tmp/freetdstest.socket&quot;</FONT><FONT color=#008a8e> dbase=</FONT><FONT color=#ff00ff>&quot;freetds&quot;</FONT><FONT color=#008a8e> connections=</FONT><FONT color=#ff00ff>&quot;3&quot;</FONT><FONT color=#008a8e> maxconnections=</FONT><FONT color=#ff00ff>&quot;5&quot;</FONT><FONT color=#008a8e> maxqueuelength=</FONT><FONT color=#ff00ff>&quot;0&quot;</FONT><FONT color=#008a8e> growby=</FONT><FONT color=#ff00ff>&quot;1&quot;</FONT><FONT color=#008a8e> ttl=</FONT><FONT color=#ff00ff>&quot;60&quot;</FONT><FONT color=#008a8e> endofsession=</FONT><FONT color=#ff00ff>&quot;commit&quot;</FONT><FONT color=#008a8e> sessiontimeout=</FONT><FONT color=#ff00ff>&quot;600&quot;</FONT><FONT color=#008a8e> runasuser=</FONT><FONT color=#ff00ff>&quot;nobody&quot;</FONT><FONT color=#008a8e> runasgroup=</FONT><FONT color=#ff00ff>&quot;nobody&quot;</FONT><FONT color=#008a8e> cursors=</FONT><FONT color=#ff00ff>&quot;5&quot;</FONT><FONT color=#008a8e> authtier=</FONT><FONT color=#ff00ff>&quot;listener&quot;</FONT><FONT color=#008a8e> handoff=</FONT><FONT color=#ff00ff>&quot;pass&quot;</FONT><FONT color=#008a8e>&gt;</FONT>
                <FONT color=#008a8e>&lt;users&gt;</FONT>
                        <FONT color=#008a8e>&lt;user user=</FONT><FONT color=#ff00ff>&quot;freetdstest&quot;</FONT><FONT color=#008a8e> password=</FONT><FONT color=#ff00ff>&quot;freetdstest&quot;</FONT><FONT color=#008a8e>/&gt;</FONT>
                <FONT color=#008a8e>&lt;/users&gt;</FONT>
                <FONT color=#008a8e>&lt;connections&gt;</FONT>
                        <FONT color=#008a8e>&lt;connection connectionid=</FONT><FONT color=#ff00ff>&quot;freetdstest&quot;</FONT><FONT color=#008a8e> string=</FONT><FONT color=#ff00ff>&quot;server=remotehost;db=testdb;user=testuser;password=testpassword&quot;</FONT><FONT color=#008a8e> metric=</FONT><FONT color=#ff00ff>&quot;1&quot;</FONT><FONT color=#008a8e>/&gt;</FONT>
                <FONT color=#008a8e>&lt;/connections&gt;</FONT>
        <FONT color=#008a8e>&lt;/instance&gt;</FONT>

<FONT color=#008a8e>&lt;/instances&gt;</FONT>
</PRE>

<p>Now you can start up this instance with the following command.</p>

<blockquote>
<b>sqlr-start -id freetdstest</b>
</blockquote>

<p>Note that there are a couple of common problems people have with the FreeTDS
connection.  See the <a href="../faq.html">FAQ</a> and the
<a href="../running.html#problems">common problems</a> section of the document
on running SQL Relay for more info.</p>

<p>To connect to the instance and run queries, use the following command.</p>

<blockquote>
<b>sqlrsh -id freetdstest</b>
</blockquote>

<p>The following command shuts down the SQL Relay instance.</p>

<blockquote>
<b>sqlr-stop freetdstest</b>
</blockquote>

</body>

</html>
